﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ddcCajamarca.BusinessEntities.Directorio;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;

namespace ddcCajamarca.Repository.Mapping
{
    public class DetalleOrganizacionContactoMap : EntityTypeConfiguration<DetalleOrganizacionContacto>
    {
        public DetalleOrganizacionContactoMap()
        {
            this.HasKey(c => c.ItemCorrelativo);

            this.Property(c => c.ItemCorrelativo)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(c => c.IdPersona)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.IdOrganizacion)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.FechaRegistro)
                .IsRequired();

            this.Property(c => c.Cargo)
                .IsOptional();

            this.Property(c => c.Estado)
                .IsRequired();

            this.ToTable("DetalleOrganizacionPersona");
            this.Property(c => c.ItemCorrelativo).HasColumnName("ItemCorrelativo");
            this.Property(c => c.IdPersona).HasColumnName("IdPersona");
            this.Property(c => c.IdOrganizacion).HasColumnName("IdOrganizacion");
            this.Property(c => c.FechaRegistro).HasColumnName("FechaRegistro");
            this.Property(c => c.Cargo).HasColumnName("Cargo");
            this.Property(c => c.Estado).HasColumnName("Estado");

            this.HasRequired(c => c.Persona)
                .WithMany(c => c.DetalleOrganizacionContactos)
                .HasForeignKey(c => c.IdPersona)
                .WillCascadeOnDelete(false);
            this.HasRequired(c => c.Organizacion)
                .WithMany(c => c.DetalleOrganizacionContactos)
                .HasForeignKey(c => c.IdOrganizacion)
                .WillCascadeOnDelete(false);
        }
    }
}
